package com.nf.xiaomi.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nf.mvc.support.ResponseVO;
import com.nf.mvc.view.JsonViewResult;
import static com.nf.mvc.handler.HandlerHelper.json;


public class JsonUtils {
    static ObjectMapper mapper=new ObjectMapper();

    public static <T> T readValue(String json, Class<T> clz){
        try {
            return mapper.readValue(json, clz);
        } catch (JsonProcessingException e) {
            System.out.println("json转换异常:"+e.getMessage());
        }
        return null;
    }
    public static String writeValueAsString(Object value){
        try {
            return mapper.writeValueAsString(value);
        } catch (JsonProcessingException e) {
            System.out.println("json转换异常:"+e.getMessage());
        }
        return null;
    }
    public static JsonViewResult Result(int result){
        if (result != 1){
            return json(new ResponseVO(500,"no",false));
        }
        return json(new ResponseVO(200,"ok",true));
    }
}
